import { createRouter, createWebHashHistory } from "vue-router";
import { useCounterStore } from "@/stores/counter";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/small",
    },
    {
      path: "/small",
      component: () => import("@/views/small-screen/home.vue"),
    },
    {
      path: "/small/disclaimer",
      component: () => import("@/views/small-screen/disclaimer.vue"),
    },
    {
      path: "/small/gender",
      component: () => import("@/views/small-screen/gender.vue"),
    },
    {
      path: "/small/camera",
      component: () => import("@/views/small-screen/camera.vue"),
    },
    {
      path: "/small/location",
      component: () => import("@/views/small-screen/location.vue"),
    },
    {
      path: "/small/result",
      component: () => import("@/views/small-screen/result.vue"),
    },
    {
      path: "/small/share",
      component: () => import("@/views/small-screen/share.vue"),
    },
    {
      path: "/big/",
      component: () => import("@/views/big-screen/home.vue"),
    },
    {
      path: "/counter-demo",
      component: () => import("@/views/CounterDemo.vue"),
    },
  ],
});

router.beforeEach((to, from, next) => {
  const counterStore = useCounterStore();
  if (counterStore.clearHistoryFlag) {
    counterStore.setClearHistoryFlag(false);
    next({ ...to, replace: true });
  } else {
    next();
  }
});

export default router;
